package screens;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import resources.Music;
import resources.Sound;
import resources.Sprite;
import tools.GameApplet;
import abstracts.Level;
import abstracts.Screen;

/** Loads all resources and displays a "Loading..." message. */
public class LoadingScreen extends Screen {
    /**
     * @param gameApplet - the {@link GameApplet} which this screen is
     *            to be displayed in.
     */
    public LoadingScreen(final GameApplet gameApplet) {
        super(gameApplet);
    }

    @Override
    public final synchronized void step() {
        // Load resources
        Music.loadAll();
        Music.set(Music.MAIN_MENU);

        Sprite.loadAll();
        Sound.loadAll(getApplet());

        // Go to main menu
        getApplet().setScreen(new MenuScreen(getApplet()));
    }

    @Override
    public final synchronized void draw(final Graphics g) {
        final String text = "Merlin's Revenge is loading please wait.";
        final int fontSize = 12;
        g.setColor(Color.BLACK);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.setColor(Color.WHITE);
        g.setFont(new Font("Georgia", Font.BOLD, fontSize));
        int w = g.getFontMetrics().stringWidth(text);
        int h = g.getFontMetrics().getHeight();
        g.drawString(text, (getWidth() - w) / 2, (getHeight() + h) / 2);
    }

    @Override
    public final int getWidth() {
        return Level.WIDTH;
    }

    @Override
    public final int getHeight() {
        return Level.HEIGHT;
    }
}
